package wlpc;

import java.io.IOException;
import java.net.*;

public class send {
    public static void main(String[] args) throws IOException {
        //发送数据
        //1.创建DatagramSocket对象
        DatagramSocket ds = new DatagramSocket();

        String str = "hahaha.";
        byte[] bytes = str.getBytes();

        InetAddress address = InetAddress.getByName("127.0.0.1");
        //绑定端口
        int port = 10086;
        //空参：可用端口中的随机一个进行使用
        //无参：指定端口号进行绑定
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, port);

        ds.send(dp);
        ds.close();
    }
}
